/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.com.dados.pedagogico;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.mysql.jdbc.Driver;
import java.sql.Statement;

/**
 *
 * @author Giane
 */
public class IdiomaDao {

    public ArrayList<String> consultaIdioma() throws SQLException {
        Connection conexao;
        ArrayList<String> result = new ArrayList<String>();
        String select_ano = "SELECT idm_descricao FROM idm_idioma;";
        String url = "jdbc:mysql://localhost/bdeng2";
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        //Class.forName("com.mysql.jdbc.Driver");
        conexao = DriverManager.getConnection(url, "root", "dados");
        //System.out.println("2 - " + select_ano);

        PreparedStatement stmt = conexao.prepareStatement(select_ano);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            result.add(rs.getString(1));
            // System.out.println(rs.getString(1));
        }

        conexao.close();
        return result;

    }

    public void inserirNivel(ArrayList<String> idiomas) throws SQLException {

        for (int i = 0; i < idiomas.size(); i++) {
            Connection conexao;
            String inserir_nivel = "insert into idm_idioma (idm_descricao) values ('" +idiomas.get(i) +"');";
            String url = "jdbc:mysql://localhost/bdeng2";
            DriverManager.registerDriver(new com.mysql.jdbc.Driver());
            conexao = DriverManager.getConnection(url, "root", "dados");


            Statement stmt2 = (Statement) conexao.createStatement();
            stmt2.execute(inserir_nivel);
            conexao.close();
        }

        /*Connection conexao;
        
         String inserir_nivel = "";

         String url = "jdbc:mysql://localhost/bdeng2";
         DriverManager.registerDriver(new com.mysql.jdbc.Driver());
         conexao = DriverManager.getConnection(url, "root", "dados");


         Statement stmt2 = (Statement) conexao.createStatement();
         stmt2.execute(inserir_nivel);
         conexao.close();*/
    }
}
